<?php
class Grant extends Action {
	private $privileges;
	/*
	 * (non-PHPdoc) @see Action::execute()
	 */
	public function execute($params) {
		$me = check_login ( ADMIN_LOGIN_PAGE );
		if (! icando ( 'grant', 'user' )) {
			Response::errorPage ( '你无权进行系统授权');
		}
		$type = rqst ( 'type' );
		$uid = rqst ( 'uid' );
		$data ['type'] = $type;
		$data ['uid'] = $uid;
		$data ['items'] = apply_filter ( 'get_rbac_resources', array () );
		$rbac = get_rbac_driver ();
		$this->privileges = $rbac->privileges ( $uid, $type );
		$data ['grant'] = $this;
		return new SmartyView ( $data, 'dashboard/Grant' );
	}
	public function priority($resource, $op) {
		$id = $resource . '@' . $op;
		if (isset ( $this->privileges [$id] )) {
			return $this->privileges [$id] ['priority'];
		} else {
			return 9999;
		}
	}
	
	public function allow($resource, $op) {
		$id = $resource . '@' . $op;
		if (isset ( $this->privileges [$id] )) {
			return $this->privileges [$id] ['allow'];
		} else {
			return - 1;
		}
	}
}